using System;
using System.Collections.Generic;
using TTDotNet.Util;

namespace TTDotNet.Engine
{
    public class CatchmentArea
    {
        private Coordinate start;
        private Coordinate end;
        private int catchmentSize;

        private Coordinate catchmentStart;
        private Coordinate catchmentEnd;

        public CatchmentArea(Coordinate start, Coordinate end, int size)
        {
            this.catchmentSize = size;

            if (start.X <= end.X)
            {
                this.start = start;
                this.end = end;
            }
            else
            {
                this.start = end;
                this.end = start;
            }

            AdjustCatchmentSize(size);

        }

        private void AdjustCatchmentSize(int size)
        {
            catchmentStart = new Coordinate(start.X - size, start.Z - size);
            catchmentEnd = new Coordinate(end.X + size, end.Z + size);
        }

        public bool Contains(Coordinate coord)
        {
            return ((coord.X >= catchmentStart.X) && (coord.X <= catchmentStart.X + catchmentEnd.X) && (coord.Z >= catchmentStart.Z) && (coord.Z <= catchmentEnd.Z));
        }

        public override string ToString()
        {
            return "Start: " + catchmentStart.ToString() + " to " + "End: " + catchmentEnd.ToString();
        }
        
    }
}
